<template>
  <a-modal
    centered
    :width="1200"
    :title="title"
    :visible="visible"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
      <span style="width: 11%">出库备注：</span>
      <a-input style="width: 60%" disabled v-model="tempData"/>
    <br>
<!--    <span style="width: 11%">操作人：</span>-->
<!--    <a-input style="width: 20%"  v-model="createBy"/>-->
<!--    <br>-->
<!--    <span style="width: 11%">操作时间：</span>-->
<!--    <a-input style="width: 20%"  v-model="createTime"/>-->
    <br>
    <a-table
      size="small"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :scroll="{ x: 1100,y: 390 }"
      >

    </a-table>
    <!-- table区域-end -->
  </a-modal>
</template>

<script>
import {filterObj} from '@/utils/util'
import {httpAction} from '@/api/manage'
import {getAction} from '@/api/manage'
import pick from 'lodash.pick'
import moment from 'moment'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'


export default {
  components: {
  },
  name: 'StmStockInRecordModalJX',
  mixins: [JeecgListMixin],
  data() {
    return {
      tempData:"",
      createBy:"",
      createTime:"",
      labelCol: {
        xs: {span: 24},
        sm: {span: 2},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 10},
      },
      title: "出库记录",
      names: [],
      visible: false,
      placement: 'right',
      description: '',
      // 查询条件
      queryParam: {},
      form: this.$form.createForm(this),
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 40,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '记录id',
          align: 'center',
          width:60,
          dataIndex: 'newId'
        },
        {
          title: '商品名称',
          align: 'center',
          width:200,
          dataIndex: 'productName'
        },
        {
          title: '货号',
          align: 'center',
          width:130,
          dataIndex: 'productSn'
        },
        {
          title: '物料编码',
          align: 'center',
          width:130,
          dataIndex: 'skuCode'
        },
        {
          title: '出库数量',
          align: 'center',
          width:70,
          dataIndex: 'inoutQty'
        },
        {
          title: '操作人',
          align: 'center',
          width:100,
          dataIndex: 'createBy'
        },
        {
          title: '操作时间',
          align: 'center',
          width:150,
          dataIndex: 'createTime'
        }
      ],
      //数据集
      dataSource: [],
      dataSource2: [],
      // 分页参数
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '30', '50'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      isorter: {
        column: 'createTime',
        order: 'desc',
      },
      mainId: '',
      loading: false,
      selectedRowKeys: [],
      selectedRows: [],
      url: {
        list: '/stm/stmStockInout/queryItemlistByRelationId',
      }
    }
  },
  methods: {
    show(record) {
      console.log(record);
      this.queryParam = {};
      this.visible = true
      this.model = Object.assign({}, record);
      //console.log('this.model.processStatus',this.model.processStatus)
      // 加载子表数据
      if (this.model.id) {
        console.log(this.model.id)
        this.loadData(1);
      }
      this.tempData=record.note;
      this.createBy=record.createBy;
      this.createTime=record.createTime;
    },
    onChangeCheckbox(e) {
      if(e.target.checked) {
        this.queryParam.publishStatus=1;
      }else {
        this.queryParam.publishStatus=null;
      }
    },
    handleCancel() {
      this.visible = false;
    },
    handleOk() {
      //this.dataSource2 = this.selectedRows;
      console.log("data:" + this.dataSource2);
      this.$emit("selectFinished", this.dataSource2);
      this.visible = false;
    },
    loadData(arg) {
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      this.queryParam.id = this.model.id;
      let param = Object.assign({}, this.queryParam, this.isorter);
      param.field = this.getQueryField();
      getAction(this.url.list, param).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records;
          this.ipagination.total = res.result.total;
        }
      })
    },
    getQueryField() {
      //TODO 字段权限控制
    },
    onSelectAll(selected, selectedRows, changeRows) {
      if (selected === true) {
        for (var a = 0; a < changeRows.length; a++) {
          this.dataSource2.push(changeRows[a]);
        }
      } else {
        for (var b = 0; b < changeRows.length; b++) {
          this.dataSource2.splice(this.dataSource2.indexOf(changeRows[b]), 1);
        }
      }
      // console.log(selected, selectedRows, changeRows);
    },
    onSelect(record, selected) {
      if (selected === true) {
        this.dataSource2.push(record);
      } else {
        var index = this.dataSource2.indexOf(record);
        //console.log();
        if (index >= 0) {
          this.dataSource2.splice(this.dataSource2.indexOf(record), 1);
        }

      }
    }
  }
}
</script>
<style lang="less" scoped>
.ant-card-body .table-operator {
  margin-bottom: 18px;
}

.ant-table-tbody .ant-table-row td {
  padding-top: 15px;
  padding-bottom: 15px;
}

.anty-row-operator button {
  margin: 0 5px
}

.ant-btn-danger {
  background-color: #ffffff
}

.ant-modal-cust-warp {
  height: 100%
}

.ant-modal-cust-warp .ant-modal-body {
  height: calc(100% - 110px) !important;
  overflow-y: auto
}

.ant-modal-cust-warp .ant-modal-content {
  height: 90% !important;
  overflow-y: hidden
}
</style>
